package com.vehicle.cards.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.vehicle.cards.perpetual.MyPerpetual;
import com.vehicle.cards.utils.HttpUtils;
import com.vehicle.cards.utils.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.vehicle.cards.mapper.TIdCardsMapper;
import com.vehicle.cards.domain.TIdCards;
import com.vehicle.cards.service.ITIdCardsService;

/**
 * 身份证Service业务层处理
 *
 * @author XU
 * @date 2025-03-28
 */
@Service
public class TIdCardsServiceImpl implements ITIdCardsService
{
    @Autowired
    private TIdCardsMapper tIdCardsMapper;

    /**
     * 查询身份证
     *
     * @param idCardId 身份证主键
     * @return 身份证
     */
    @Override
    public TIdCards selectTIdCardsByIdCardId(Long idCardId)
    {
        return tIdCardsMapper.selectTIdCardsByIdCardId(idCardId);
    }

    /**
     * 查询身份证列表
     *
     * @param tIdCards 身份证
     * @return 身份证
     */
    @Override
    public List<TIdCards> selectTIdCardsList(TIdCards tIdCards)
    {
        return tIdCardsMapper.selectTIdCardsList(tIdCards);
    }

    /**
     * 新增身份证
     *
     * @param tIdCards 身份证
     * @return 结果
     */
    @Override
    public int insertTIdCards(TIdCards tIdCards)
    {
        return tIdCardsMapper.insertTIdCards(tIdCards);
    }

    /**
     * 修改身份证
     *
     * @param tIdCards 身份证
     * @return 结果
     */
    @Override
    public int updateTIdCards(TIdCards tIdCards)
    {
        return tIdCardsMapper.updateTIdCards(tIdCards);
    }

    /**
     * 批量删除身份证
     *
     * @param idCardIds 需要删除的身份证主键
     * @return 结果
     */
    @Override
    public int deleteTIdCardsByIdCardIds(Long[] idCardIds)
    {
        return tIdCardsMapper.deleteTIdCardsByIdCardIds(idCardIds);
    }

    /**
     * 删除身份证信息
     *
     * @param idCardId 身份证主键
     * @return 结果
     */
    @Override
    public int deleteTIdCardsByIdCardId(Long idCardId)
    {
        return tIdCardsMapper.deleteTIdCardsByIdCardId(idCardId);
    }

    @Override
    public String humanFace(String uploadFile) {
        String timestamp = System.currentTimeMillis() + "";
//        String motions = "用户动作序列，BLINK 眨眼；MOUTH 张嘴； NOD 点头；YAW 摇头";
//        String motions = "BLINK";
//        String complexity = "活体检测通过的难易程度，默认为0， 0：简单模式；1：正常模式；2：困难模式；3：地狱模式";
//        String url = "https://pangtouyu-2204a.oss-cn-beijing.aliyuncs.com/blink.mp4";
//        //接口地址
//        String url = "https://api.shumaidata.com/v2/life/check";

        //MD5Utils文件请联系工作人员索取
        String sign = MD5Utils.encrypt(MyPerpetual.APP_ID+"&"+timestamp+"&"+ MyPerpetual.APPSECURITY);
        System.out.println("sign: "+sign);

        Map<String,String> headers = new HashMap<String,String>();
        headers.put("Content-Type","application/x-www-form-urlencoded");

        Map<String,Object> params = new HashMap<String,Object>();
        params.put("appid", MyPerpetual.APP_ID);
        params.put("timestamp",timestamp);
        params.put("sign",sign);
        params.put("motions", "BLINK");
        params.put("complexity", "0");
        params.put("url", uploadFile);

        //HttpUtils文件请联系工作人员索取
        String result = HttpUtils.postForm(MyPerpetual.HUMANFACE_URL,headers,params);
        System.out.println(result);
        return result;
    }
}
